//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "net\fn_callHC.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_hc_id"];
_hc_id = -1;
if (!(isNil QUOTE(MCFUNC(hasHC)))) then {
	if (0 call MCFUNC(isHC) && {!(isNil "idxHC")} && {idxHC >= 0}) then {
		// If we already are on a HC, we execute in place
		_hc_id = idxHC;
	} else {
		// if we are on a server, we check if we have HCs
		if (isServer && 0 call MCFUNC(hasHC)) then {
			// Selects a target HC
			_hc_id = 0 call MCFUNC(getHC);
		};
	};
};
if (_hc_id >= 0) then {
	TRACE_2("Calling HC",_hc_id,idxHC);
	[QGVAR(hc_execute),[_this select 0,_this select 1,_hc_id]] call FFUNC(callEvent);
} else {
	TRACE_2("Calling Server",_hc_id,idxHC);
	[QGVAR(s_execute),[_this select 1,_this select 0,_hc_id]] call FFUNC(callEvent);
};
TRACE("End");
TMFPROFILERSTOP;